package cn.lanjh.oss;

import cn.lanjh.oss.valdator.DiskGroup;
import cn.lanjh.oss.valdator.MinioGroup;
import cn.lanjh.oss.valdator.QiniuGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.hibernate.validator.constraints.URL;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotBlank;

@Data
@Component
@ConfigurationProperties(prefix = "oss", ignoreUnknownFields = false)
public class CloudStoragePropies {
    
	private int type;	
	private QiniuVo qiniu;
	private DiskVo disk;
	private MinioVo minIO;
	
	
	@Data
	public static class QiniuVo{
		  @Range(min = 1, max = 4, message = "类型错误")
		    private Integer type;

		    /**
		     * 七牛绑定的域名
		     */
		    @NotBlank(message = "七牛绑定的域名不能为空", groups = QiniuGroup.class)
		    @URL(message = "七牛绑定的域名格式不正确", groups = QiniuGroup.class)
		    private String qiniuDomain;
		    /**
		     * 七牛路径前缀
		     */
		    private String qiniuPrefix;
		    /**
		     * 七牛ACCESS_KEY
		     */
		    @NotBlank(message = "七牛AccessKey不能为空", groups = QiniuGroup.class)
		    private String qiniuAccessKey;
		    /**
		     * 七牛SECRET_KEY
		     */
		    @NotBlank(message = "七牛SecretKey不能为空", groups = QiniuGroup.class)
		    private String qiniuSecretKey;
		    /**
		     * 七牛存储空间名
		     */
		    @NotBlank(message = "七牛空间名不能为空", groups = QiniuGroup.class)
		    private String qiniuBucketName;

	}
	
	 
	@Data
	public static class DiskVo{
		  /**
	     * 服务器存储
	     */
	    @NotBlank(message = "本地存储路径不能为空", groups = DiskGroup.class)
	    private String diskPath;
	    @NotBlank(message = "本地存储代理服务器不能为空", groups = DiskGroup.class)
	    private String proxyServer;
	    
	    
	}
	
	 
	@Data
	public static class MinioVo{
		 /**
	     *  minIO绑定的域名
	     */
	    @NotBlank(message = " minIO绑定的域名不能为空", groups = MinioGroup.class)
	    @URL(message = " minIO绑定的域名格式不正确", groups = MinioGroup.class)
	    private String minioDomain;
	    /**
	     *  minIO路径前缀
	     */
	    private String minioPrefix;
	    /**
	     *  minIOACCESS_KEY
	     */
	    @NotBlank(message = "minIOAccessKey不能为空", groups = MinioGroup.class)
	    private String minioAccessKey;
	    /**
	     *  minIO SECRET_KEY
	     */
	    @NotBlank(message = "minIOSecretKey不能为空", groups = MinioGroup.class)
	    private String minioSecretKey;
	    /**
	     * minIO存储空间名
	     */
	    @NotBlank(message = "minIO空间名不能为空", groups = MinioGroup.class)
	    private String minioBucketName;
	    
		@NotBlank(message = "minIO代理服务不能为空", groups = MinioGroup.class)
		private String minioProxyServer;
	}


	public CloudStorageConfig getCloudStorageConfig() {
		CloudStorageConfig cloudStorageConfig = new CloudStorageConfig();
		if (this.getType() == CloudConstant.CloudService.QINIU.getValue()) {
			BeanUtils.copyProperties(this.getQiniu(), cloudStorageConfig);
		} else if (this.getType() == CloudConstant.CloudService.DISK.getValue()) {
			BeanUtils.copyProperties(this.getDisk(), cloudStorageConfig);
		} else if (this.getType() == CloudConstant.CloudService.MINIO.getValue()) {
			BeanUtils.copyProperties(this.getMinIO(), cloudStorageConfig);
		}
		cloudStorageConfig.setType(this.getType());
		return cloudStorageConfig;
	}
}
